﻿package com.mr_ladeng.listview;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;


/**
 * 
 * @项目名称： Wo24Sh
 * @类名称： JsonUtils.java
 * @创建人： Mr.ladeng (zbl704@yeah.net)
 * @创建时间： 2015-1-7下午9:24:39
 * @修改备注：
 * @version 1.0
 * @类描述： 获取json数据
 */
public class JsonUtils {

	public static JSONObject ReadHttpGet(String path) {
		HttpGet httpRequest = new HttpGet(path);
		HttpParams connParam = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(connParam, 5 * 1000);
		HttpConnectionParams.setSoTimeout(connParam, 5 * 1000);
		HttpClient httpClient = new DefaultHttpClient(connParam);
		JSONObject jsonObject = null;
		try {
			HttpResponse httpResponse = httpClient.execute(httpRequest);
			if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				String strResult = EntityUtils.toString(httpResponse
						.getEntity());
				jsonObject = new JSONObject(strResult);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			// 释放资源
			httpClient.getConnectionManager().shutdown();
		}

		return jsonObject;
	}

	

}
